package com.kafka_test.app.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Mapper
@Repository("OffsetMapper")
public interface OffsetMapper {
    @Select("select offset from offsetmanager where tablename=#{tableName}")
    Object getOffset(String tableName);

    @Insert("insert into offsetmanager(tablename,offset) values(#{tableName},#{offset})")
    void initializeOffset(String tableName,long offset);

    @Select("SELECT * from  ${tableName} where id_producer > #{offset} order by id_producer")
    List<Map<String, Object>> queryTableData(String tableName,long offset);

    @Update("update offsetmanager set offset=#{offset} where tablename=#{tableName}")
    void updateOffset(String tableName,long offset);

    @Insert("insert into ${tableName} (${column}) values(#{value})")
    void insertConsumer(String tableName, String column, Object value);
}
